home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13995 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
  2. From: grantp@usa.pipeline.com(Pete Grant)
  3. Newsgroups: comp.lang.c++,
  4. Subject: Re: template problem
  5. Date: 28 Mar 1996 11:37:31 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4jdtlr$21r@news1.h1.usa.pipeline.com>
  8. References: <4jd9dv$27g@mirv.unsw.edu.au>
  9. NNTP-Posting-Host: 38.8.60.8
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete Grant)
  13. X-Newsreader: Pipeline v3.5.0
  14.  
  15. On Mar 28, 1996 05:51:59 in article <template problem>,
  16. 'jeroen@fatboy.gas.unsw.edu.au (Jeroen Dijkmeijer)' wrote: 
  17.  
  18.  
  19. >Problem with templates and friend declaration 
  20. >G'day 
  21. >I haven't much of C++ experience. But I'm studying hard to learn. At this 
  22.  
  23. >moment I do have a problem with templates. The example is taken from
  24. Deitel &  
  25. >Deitel C++ how to program ch 15 pg 697 
  26. >The files are listed below. 
  27. >// file listnode.h 
  28. >// List template definition 
  29. >#ifndef LISTNODE_H 
  30. >#define LISTNODE_H 
  31. >template<class DATA_TYPE> 
  32. >class ListNode {   
  33. >friend class List<DATA_TYPE>; 
  34. >public: 
  35. >ListNode(const DATA_TYPE &); //constructor 
  36. >DATA_TYPE getData() const; 
  37. >private: 
  38. >DATA_TYPE data;              // data 
  39. >ListNode *nextPtr; 
  40. >}; 
  41.  [... rest of code deleted ..] 
  42.  
  43. >"listnode.h", line 9: error(3358): invalid friend declaration 
  44. >friend class List<DATA_TYPE>; 
  45.  
  46. You need a forward declaration for template class List: 
  47.  
  48. template<class T> class List; 
  49.  
  50. Place it in file listnode.h after the line #define LISTNODE_H 
  51.  
  52. -- 
  53. Pete Grant 
  54. Kalevi, Inc. 
  55. Software Engineering & development
  56.